package io.renren.common.gvy;

import groovy.util.GroovyScriptEngine;
import groovy.util.ResourceException;
import groovy.util.ScriptException;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class GroovyCollectionFilterDemo {
    public static void main(String[] args) {
        try {
            // 创建Groovy脚本引擎，指定脚本搜索路径
            GroovyScriptEngine gse = new GroovyScriptEngine("renren-admin/src/main/resources/groovy-scripts/");
            // 准备要传递给脚本的参数
            List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

            groovy.lang.Binding binding = new groovy.lang.Binding();
            binding.setVariable("numberList", numberList);

            // 执行脚本并获取结果
            Object result = gse.run("groovy_script_03.groovy", binding);
            // 输出结果
            // 输出结果
            System.out.println("原始集合: " + numberList);
            System.out.println("过滤后的偶数集合: " + result);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ScriptException e) {
            throw new RuntimeException(e);
        } catch (ResourceException e) {
            throw new RuntimeException(e);
        }
    }
}
